﻿var table;//要删除的table
var row; //要删除的table的行
var did; //编辑时保存的院系编号
var jid; //编辑时保存的机构编号
var uid; //编辑时保存的作者编号
var aid;//作者在数据表中的主键，修改时作为标识传参
var contribution=100; //总贡献率
var contribution_temp = 0;

//检查论文添加表单
function checkForm() {
    var fg = true;
    if (!error) {
        fg = verifyInput("title_cn", "论文标题", "NO", "", 0, 100, "");
    }
    if (!error) {
        fg = verifyInput("publication", "发表刊物/论文集", "NO", "", 0, 25, "");
    }
    if (!error) {
        fg = verifyInput("publication_grade", "刊物级别", "NO", "", "", "", "");
    }
    if (!error) {
        fg = verifyInput("publication_num", "期号", "NO", "", 0, 25, "");
    }
    if (!error) {
        if ($("wordnum").value != "") {
            fg = verifyInput("wordnum", "字数", "YES", "NUM", "", "", "");
        }
    }
    if (!error) {
        if ($("publication_time").value != "") {
            fg = verifyInput("publication_time", "发表时间", "YES", "DATE", "", "", "");
        }
    }
    if (!error) {
        fg = verifyInput("firstsubject", "一级学科", "NO", "", "", "", "");
    }
    if (!error) {
        fg = verifyInput("pagerange", "页码范围", "NO", "", "", "", "");
    }
    if (!error) {
        fg = verifyInput("publishrange", "发表范围", "NO", "", "", "", "");
    }
    if (!error) {
        fg = verifyInput("publication_time", "发表/出版时间", "NO", "", "", "", "");
    }
    
    if (!error) {
        if ($("personnum").value != "") {
            fg = verifyInput("personnum", "参编人数", "YES", "INT", "", "", "");
        }
    }
    if (!error) {
        if ($("fittings1").value != "") {
            var vstr=$("fittings1").value;
            if (vstr.substring(vstr.lastIndexOf(".") + 1).toLowerCase() != "rar" && vstr.substring(vstr.lastIndexOf(".") + 1).toLowerCase() != "zip") {
                alert("附件1格式不合法");
                document.getElementById("fittings1").focus();
                fg = false;
                error = true;
            }
            else {
                if ($("filename1").value == "") {
                    alert("附件1文件名不能为空");
                    document.getElementById("filename1").focus();
                    fg = false;
                    error = true;
                }
            }
        }
    }
    if (!error) {
        if ($("fittings2").value != "") {
            var vstr = $("fittings2").value;
            if (vstr.substring(vstr.lastIndexOf(".") + 1).toLowerCase() != "rar" && vstr.substring(vstr.lastIndexOf(".") + 1).toLowerCase() != "zip") {
                alert("附件2格式不合法");
                document.getElementById("fittings2").focus();
                fg = false;
                error = true;
            }
            else {
                if ($("filename2").value == "") {
                    alert("附件2文件名不能为空");
                    document.getElementById("filename2").focus();
                    fg = false;
                    error = true;
                }
            }
        }
    }
    if (!error) {
        if ($("fittings3").value != "") {
            var vstr = $("fittings3").value;
            if (vstr.substring(vstr.lastIndexOf(".") + 1).toLowerCase() != "rar" && vstr.substring(vstr.lastIndexOf(".") + 1).toLowerCase() != "zip") {
                alert("附件3格式不合法");
                document.getElementById("fittings3").focus();
                fg = false;
                error = true;
            }
            else {
                if ($("filename3").value == "") {
                    alert("附件3文件名不能为空");
                    document.getElementById("filename3").focus();
                    fg = false;
                    error = true;
                }
            }
        }
    }
    error = false;
    return fg;
}

//显示添加作者窗口
function showAuthor() {
    $("bgdiv").style.height = document.documentElement.scrollHeight;
    //控制页面SELECT元素
    $("publication_grade").style.display = "none";
    $("publishrange").style.display = "none";
    $("schoolsign").style.display = "none";
    $("firstsubject").style.display = "none";
    $("itemsource").style.display = "none";
    $("sheet").style.display = "none";
    
    $("bgdiv").style.display = "block";
    $("author").style.left = (document.documentElement.clientWidth + document.documentElement.scrollLeft * 1.8 - 450) / 2 + "px";
    $("author").style.top = (document.documentElement.clientHeight + document.documentElement.scrollTop * 1.8 - 250) / 2 + "px";
    $("author").style.display = "block";
    var r = document.getElementsByName("author_type");
    for (var i = 0; i < r.length; i++) {
       //设置作者类型可选
        r[i].disabled = false;
    }
    DepartmentBind();
    $("btnarea").innerHTML = "<a href='javascript:void(0);' onclick='saveAuthor()' style='text-decoration: none;' onfocus='this.blur()' class='fontbutton'>保 存</a><a href='javascript:void(0);' onclick='closeAuthor()' style='text-decoration: none; margin-left:15px;' class='fontbutton' onfocus='this.blur()'>关 闭</a>";
}

//关闭添加作者窗口
function closeAuthor() {
    //撤销控制页面SELECT元素
    $("publication_grade").style.display = "";
    $("publishrange").style.display = "";
    $("schoolsign").style.display = "";
    $("firstsubject").style.display ="";
    $("itemsource").style.display = "";
    $("sheet").style.display = "";
    
    $("bgdiv").style.display = "none";
    $("author").style.display = "none";
    $("loginstate").innerHTML = "";
    
    //清空表单内容
    $("Department").length = 0;
    AddOption("请选择", "", "Department");
    $("institution").length = 0;
    AddOption("请选择", "", "institution");
    $("aut").length = 0;
    AddOption("请选择", "", "aut");
    $("issign").checked = "checked";
    $("signorder0").value = "";
    $("rate0").value = "";
    $("note0").value = "";
    $("anum").value = "";
    $("aname1").value = "";
    $("subject").value = "";
    $("class").value = "";
    $("sex1").checked = "checked";
    $("tel1").value = "";
    $("addr1").value = "";
    $("rate1").value = "";
    $("signorder1").value = "";
    $("note1").value = "";
    $("aname2").value = "";
    $("educational").value = "";
    $("company").value = "";
    $("sex2").checked = "checked";
    $("professional").value = "";
    $("citizenship").value = "";
    $("tel2").value = "";
    $("addr2").value = "";
    $("rate2").value = "";
    $("signorder2").value = "";
    $("note2").value = "";
}

//设置当前作者类型表单
function setAuthor(index) {
    for (i = 0; i < 3; i++)
    {
        $("type" + i).style.display = "none";
    }
    $("type" + index).style.display = "block";
}

//绑定院系信息
function DepartmentBind() {
    var url = "Handler.ashx";
    var pars = "act=GetDepartment";
    Ajax(url, pars, "get", DepartmentBind_Complete, DepartmentBind_Wait, true);
    url = null;
    pars = null;
}

function DepartmentBind_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location="../index.html";
    }
    else if (req.responseText != "")
    {
        var num = 0;
        eval("s =" + req.responseText);
        num = s.num;
        $("Department").length = 0;
        AddOption("请选择", "", "Department");
        if (num > 0) {
            for (i = 0; i < num; i++) {
                AddOption(s.lists[i].name, s.lists[i].id, "Department");
            }
        }
        //如果是编辑状态，判断是否要选中相应的院系
        if (did != null&&did!="") {
            SetOptionToSelect($("Department"), did);
            did = null;
        }
    }
}

function DepartmentBind_Wait() { 

}

//获取机构列表；index指院系编号
function getInstitution(index) {
    if (index != "") {
        var url = "Handler.ashx";
        var pars = "act=GetInstitution&index=" + index;
        Ajax(url, pars, "get", getInstitution_Complete, getInstitution_Wait, true);
        url = null;
        pars = null;
    }
    else {
        $("institution").length = 0;
        AddOption("请选择", "", "institution");
    }
}

function getInstitution_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location="../index.html";
    }
    else if (req.responseText != "")
    {
        var num = 0;
        eval("s =" + req.responseText);
        num = s.num;
        $("institution").length = 0;
        AddOption("请选择", "", "institution");
        if (num > 0) {
            for (i = 0; i < num; i++) {
                AddOption(s.lists[i].name, s.lists[i].id, "institution");
            }
        }
        $("aut").length = 0;
        AddOption("请选择", "", "aut");
        //如果是编辑状态，判断是否要选中相应的机构
        if (jid != null && jid != "") {
            SetOptionToSelect($("institution"), jid);
            //jid = null;
            getAut(jid); //加载机构下的作者
        }
    }
}

function getInstitution_Wait() {
}


//获取机构作者列表；index指机构编号
function getAut(index) {
    if (index != "") {
        var url = "Handler.ashx";
        var pars = "act=GetAut&index=" + index;
        Ajax(url, pars, "get", getAut_Complete, getAut_Wait, true);
        url = null;
        pars = null;
    }
    else {
        $("aut").length = 0;
        AddOption("请选择", "", "aut");
    }
}

function getAut_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location = "../index.html";
    }
    else if (req.responseText != "") {
        var num = 0;
        eval("s =" + req.responseText);
        num = s.num;
        $("aut").length = 0;
        AddOption("请选择", "", "aut");
        if (num > 0) {
            for (i = 0; i < num; i++) {
                AddOption(s.lists[i].name, s.lists[i].id, "aut");
            }
        }
        //如果是编辑状态，判断是否要选中相应的作者
        if (uid != null && uid != "") {
            SetOptionToSelect($("aut"), uid);
            uid = null;
        }
    }
}

function getAut_Wait() {
}

//检查作者添加表单
function checkAuthor(index) {
    var fg=true;
    if(index==0) {
        if (!error) {
            fg = verifyInput("Department", "院系", "NO", "", "", "", "");
        }
        if (!error) {
            fg = verifyInput("institution", "机构", "NO", "", "", "", "");
        }
        if (!error) {
            fg = verifyInput("aut", "作者", "NO", "", "", "", "");
        }
        if (!error) {
            fg = verifyInput("signorder0", "署名顺序", "NO", "INT", "1", "2", "");
        }
        if (!error) {
            fg = verifyInput("rate0", "贡献率", "NO", "INT", "1", "3", "");
        }
        if (!error) {
            if ($("note0").value != "") {
                fg = verifyInput("note0", "备注", "YES", "", "1", "200", "");
            }
        }
    }
    else if (index == 1) {
        if (!error) {
            fg = verifyInput("anum", "学号", "NO", "", "", "", "");
        }
        if (!error) {
            fg = verifyInput("aname1", "姓名", "NO", "", "", "", "");
        }
        if (!error) {
            fg = verifyInput("subject", "专业", "NO", "", "", "", "");
        }
        if (!error) {
            fg = verifyInput("class", "班级", "NO", "", "", "", "");
        }
        if (!error) {
            fg = verifyInput("rate1", "贡献率", "NO", "INT", "1", "3", "");
        }
        if (!error) {
            fg = verifyInput("signorder1", "署名顺序", "NO", "INT", "1", "2", "");
        }
        if (!error) {
            if ($("note1").value != "") {
                fg = verifyInput("note1", "备注", "YES", "", "1", "200", "");
            }
        }
    }
    else if (index == 2) {
        if (!error) {
            fg = verifyInput("aname2", "姓名", "NO", "", "", "", "");
        }
        if (!error) {
            fg = verifyInput("citizenship", "身份证", "NO", "CARD", "", "", "");
        }
        if (!error) {
            fg = verifyInput("rate2", "贡献率", "NO", "INT", "1", "3", "");
        }
        if (!error) {
            fg = verifyInput("signorder2", "署名顺序", "NO", "INT", "1", "2", "");
        }
        if (!error) {
            if ($("note2").value != "") {
                fg = verifyInput("note2", "备注", "YES", "", "1", "200", "");
            }
        }
    }
    error = false;
    return fg;
}


//保存本校老师作者
function saveAut0() {
    if((contribution_temp + parseInt($("rate0").value)) <= contribution)
    {
        var issign_value = "";
        var r = document.getElementsByName("issign");
        for (var i = 0; i < r.length; i++) {
            if (r[i].checked) {
                issign_value = r[i].value;
            }
        }
        r = null;
        var url = "Handler.ashx";
        var pars = "act=SaveAut0&id=" + $("code").value + "&aut=" + $("aut").options[document.getElementById('aut').selectedIndex].value + "&signorder=" + $("signorder0").value + "&rate=" + $("rate0").value + "&issign=" + issign_value + "&note=" + escape($("note0").value);
        Ajax(url, pars, "get", saveAut0_Complete, saveAut0_Wait, true);
        url = null;
        pars = null;
    }
    else
    {
        alert("贡献率总和不能超过" + contribution+"%");
    }
}

function saveAut0_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location = "../index.html";
    }
    else if (req.responseText == "repeat") {
        $("loginstate").innerHTML = "作者重复";
    }
    else if (req.responseText == "true") {
        $("loginstate").innerHTML = "保存成功";
        addrow("autlist", new Array($("signorder0").value, $("aut").options[document.getElementById("aut").selectedIndex].text, $("Department").options[document.getElementById('Department').selectedIndex].text, $("rate0").value + "%", "本校老师", "<a href='javascript:void(0);' onclick=\"showEdit('" + $("aut").options[document.getElementById("aut").selectedIndex].value + "','" + $("code").value + "',0,this.parentNode.parentNode)\">编辑</a>&nbsp;<a href='javascript:void(0);' onclick=\"if(confirm('确定删除该作者吗？'))autDel0('" + $("aut").options[document.getElementById("aut").selectedIndex].value + "','" + $("code").value + "',this.parentNode.parentNode.parentNode,this.parentNode.parentNode)\">删除</a>"));
        setTimeout("closeAuthor()", 200);
        getAllRate(); //计算总贡献率
    }
    else if (req.responseText == "false") {
        $("loginstate").innerHTML = "保存发生错误";
    }
}

function saveAut0_Wait() {
    $("loginstate").style.innerHTML= "<img src='../IMG/savepro.gif' />";
}

//保存本校学生作者
function saveAut1() {
    if((contribution_temp + parseInt($("rate1").value)) <= contribution)
    {
        var sex_value = "";
        var r = document.getElementsByName("sex1");
        for (var i = 0; i < r.length; i++) {
            if (r[i].checked) {
                sex_value = r[i].value;
            }
        }
        r = null;
        var url = "Handler.ashx";
        var pars = "act=SaveAut1&id=" + $("code").value + "&anum=" + escape($("anum").value) + "&aname=" + escape($("aname1").value) + "&subject=" + escape($("subject").value) + "&tel=" + escape($("tel1").value) + "&class=" + escape($("class").value) + "&sex=" + escape(sex_value) + "&addr=" + escape($("addr1").value) + "&rate=" + $("rate1").value + "&signorder=" + $("signorder1").value + "&note=" + escape($("note1").value);
        Ajax(url, pars, "get", saveAut1_Complete, saveAut1_Wait, true);
        url = null;
        pars = null;
    }
    else
    {
        alert("贡献率总和不能超过" + contribution+"%");
    }
}

function saveAut1_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location = "../index.html";
    }
    else if (req.responseText == "repeat") {
        $("loginstate").innerHTML = "作者重复";
    }
    else if (req.responseText == "true") {
        $("loginstate").innerHTML = "保存成功";
        addrow("autlist", new Array($("signorder1").value, $("aname1").value, "--" , $("rate1").value + "%", "本校学生", "<a href='javascript:void(0);' onclick=\"showEdit('" + $("anum").value + "','" + $("code").value + "',1,this.parentNode.parentNode)\">编辑</a>&nbsp;<a href='javascript:void(0);' onclick=\"if(confirm('确定删除该作者吗？'))autDel1('" + $("anum").value + "','" + $("code").value + "',this.parentNode.parentNode.parentNode,this.parentNode.parentNode)\">删除</a>"));
        setTimeout("closeAuthor()", 200);
        getAllRate(); //计算总贡献率
    }
    else if (req.responseText == "false") {
        $("loginstate").innerHTML = "保存发生错误";
    }
}

function saveAut1_Wait() {
    $("loginstate").style.innerHTML = "<img src='../IMG/savepro.gif' />";
}

//保存外校人员作者
function saveAut2() {
    if((contribution_temp + parseInt($("rate2").value)) <= contribution)
    {
        var sex_value = "";
        var r = document.getElementsByName("sex2");
        for (var i = 0; i < r.length; i++) {
            if (r[i].checked) {
                sex_value = r[i].value;
            }
        }
        r = null;
        var url = "Handler.ashx";
        var pars = "act=SaveAut2&id=" + $("code").value + "&aname=" + escape($("aname2").value) + "&educational=" + escape($("educational").value) + "&company=" + escape($("company").value) + "&tel=" + escape($("tel2").value) + "&professional=" + escape($("professional").value) + "&citizenship=" + $("citizenship").value + "&sex=" + escape(sex_value) + "&addr=" + escape($("addr2").value) + "&rate=" + $("rate2").value + "&signorder=" + $("signorder2").value + "&note=" + escape($("note2").value);
        Ajax(url, pars, "get", saveAut2_Complete, saveAut2_Wait, true);
        url = null;
        pars = null;
    }
    else
    {
        alert("贡献率总和不能超过" + contribution+"%");
    }
}

function saveAut2_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location = "../index.html";
    }
    else if (req.responseText == "repeat") {
        $("loginstate").innerHTML = "作者重复";
    }
    else if (req.responseText == "true") {
        $("loginstate").innerHTML = "保存成功";
        addrow("autlist", new Array($("signorder2").value, $("aname2").value, $("company").value, $("rate2").value + "%", "外校人员", "<a href='javascript:void(0);' onclick=\"showEdit('" + $("citizenship").value + "','" + $("code").value + "',2,this.parentNode.parentNode)\">编辑</a>&nbsp;<a href='javascript:void(0);' onclick=\"if(confirm('确定删除该作者吗？'))autDel2('" + $("citizenship").value + "','" + $("code").value + "',this.parentNode.parentNode.parentNode,this.parentNode.parentNode)\">删除</a>"));
        setTimeout("closeAuthor()", 200);
        getAllRate(); //计算总贡献率
    }
    else if (req.responseText == "false") {
        $("loginstate").innerHTML = "保存发生错误";
    }
}

function saveAut2_Wait() {
    $("loginstate").style.innerHTML = "<img src='../IMG/savepro.gif' />";
}


//本校老师作者删除
function autDel0(uid, tid, t, r) {
    table = t;
    row = r;
    var url = "Handler.ashx";
    var pars = "act=DelAut0&uid=" + uid + "&tid=" + tid;
    Ajax(url, pars, "get", autDel0_Complete, autDel0_Wait, true);
    url = null;
    pars = null;
}


function autDel0_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location = "../index.html";
    }
    else if (req.responseText == "true") {
        delrow(table, row);
        getAllRate(); //计算总贡献率
    }
    else if (req.responseText == "false") {

    }
}

function autDel0_Wait() {

}


//本校学生作者删除
function autDel1(uid, tid, t, r) {
    table = t;
    row = r;
    var url = "Handler.ashx";
    var pars = "act=DelAut1&uid=" + uid + "&tid=" + tid;
    Ajax(url, pars, "get", autDel1_Complete, autDel1_Wait, true);
    url = null;
    pars = null;
}

function autDel1_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location = "../index.html";
    }
    else if (req.responseText == "true") {
        delrow(table, row);
        getAllRate(); //计算总贡献率
    }
    else if (req.responseText == "false") {

    }
}

function autDel1_Wait() {

}

//外校人员作者删除
function autDel2(uid, tid, t, r) {
    table = t;
    row = r;
    var url = "Handler.ashx";
    var pars = "act=DelAut2&uid=" + uid + "&tid=" + tid;
    Ajax(url, pars, "get", autDel2_Complete, autDel2_Wait, true);
    url = null;
    pars = null;
}

function autDel2_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location = "../index.html";
    }
    else if (req.responseText == "true") {
        delrow(table, row);
        getAllRate(); //计算总贡献率
    }
    else if (req.responseText == "false") {

    }
}

function autDel2_Wait() {

}
//保存作者信息
function saveAuthor() {
    var index;
    var r = document.getElementsByName("author_type");
    for (var i = 0; i < r.length; i++) {
        if (r[i].checked) {
            index = i;
        }
    }
    if (index == 0 && checkAuthor(index)) {
        saveAut0();//保存本校老师作者
    }
    else if (index == 1 && checkAuthor(index)) {
        saveAut1(); //保存本校学生作者
    }
    else if (index == 2 && checkAuthor(index)) {
        saveAut2(); //保存外校人员作者
    }

}

//显示修改作者窗口
//uid:人员编号;tid:论文编号;type:作者类型;r行索引
function showEdit(uid, tid, type, r) {
    row = r;
    $("bgdiv").style.height = document.documentElement.scrollHeight;
    //控制页面SELECT元素
    $("publication_grade").style.display = "none";
    $("publishrange").style.display = "none";
    $("schoolsign").style.display = "none";
    $("firstsubject").style.display = "none";
    $("itemsource").style.display = "none";
    $("sheet").style.display = "none";

    $("bgdiv").style.display = "block";
    $("author").style.left = (document.documentElement.clientWidth + document.documentElement.scrollLeft * 1.8 - 450) / 2 + "px";
    $("author").style.top = (document.documentElement.clientHeight + document.documentElement.scrollTop * 1.8 - 250) / 2 + "px";
    $("author").style.display = "block";
    if (type == 0) {//本校老师作者的情况
        for (i = 0; i < 3; i++) {
            $("type" + i).style.display = "none";
        }
        $("type" + type).style.display = "block";
        var r = document.getElementsByName("author_type");
        for (var i = 0; i < r.length; i++) {
            if (r[i].value == "本校老师") {
                r[i].checked = true;
                r[i].disabled =false;
            }
            else {
                //设置其他作者类型不可选
                r[i].disabled = "disabled";
            }
        }
        r = null;

        $("btnarea").innerHTML = "<a href='javascript:void(0);' onclick='saveEdit0()' style='text-decoration: none;' onfocus='this.blur()' class='fontbutton'>修 改</a><a href='javascript:void(0);' onclick='closeAuthor()' style='text-decoration: none; margin-left:15px;' class='fontbutton' onfocus='this.blur()'>关 闭</a>";
        //加载本校老师作者信息
        var url = "Handler.ashx";
        var pars = "act=AutInfo0&uid=" + uid + "&tid=" + tid;
        Ajax(url, pars, "get", autInfo0_Complete, autInfo0_Wait, true);
        url = null;
        pars = null;
    }
    else if (type == 1) {
        for (i = 0; i < 3; i++) {
            $("type" + i).style.display = "none";
        }
        $("type" + type).style.display = "block";
        var r = document.getElementsByName("author_type");
        for (var i = 0; i < r.length; i++) {
            if (r[i].value == "本校学生") {
                r[i].checked = true;
                r[i].disabled = false;
            }
            else {
                //设置其他作者类型不可选
                r[i].disabled = "disabled";
            }
        }
        r = null;

        $("btnarea").innerHTML = "<a href='javascript:void(0);' onclick='saveEdit1()' style='text-decoration: none;' onfocus='this.blur()' class='fontbutton'>修 改</a><a href='javascript:void(0);' onclick='closeAuthor()' style='text-decoration: none; margin-left:15px;' class='fontbutton' onfocus='this.blur()'>关 闭</a>";
        //加载本校学生作者信息
        var url = "Handler.ashx";
        var pars = "act=AutInfo1&uid=" + uid + "&tid=" + tid;
        Ajax(url, pars, "get", autInfo1_Complete, autInfo1_Wait, true);
        url = null;
        pars = null;
    }
    else if (type == 2) {
        for (i = 0; i < 3; i++) {
            $("type" + i).style.display = "none";
        }
        $("type" + type).style.display = "block";
        var r = document.getElementsByName("author_type");
        for (var i = 0; i < r.length; i++) {
            if (r[i].value == "外校人员") {
                r[i].checked = true;
                r[i].disabled = false;
            }
            else {
                //设置其他作者类型不可选
                r[i].disabled = "disabled";
            }
        }
        r = null;

        $("btnarea").innerHTML = "<a href='javascript:void(0);' onclick='saveEdit2()' style='text-decoration: none;' onfocus='this.blur()' class='fontbutton'>修 改</a><a href='javascript:void(0);' onclick='closeAuthor()' style='text-decoration: none; margin-left:15px;' class='fontbutton' onfocus='this.blur()'>关 闭</a>";
        //加载外校人员师作者信息
        var url = "Handler.ashx";
        var pars = "act=AutInfo2&uid=" + uid + "&tid=" + tid;
        Ajax(url, pars, "get", autInfo2_Complete, autInfo2_Wait, true);
        url = null;
        pars = null;
    }
}

function autInfo0_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location = "../index.html";
    }
    else if (req.responseText != "false") {
        var infolist = req.responseText.split(",");
        did = infolist[0];
        jid = infolist[1];
        uid = infolist[2];
        //加载院系
        DepartmentBind();
        
        //加载院系下的机构
        getInstitution(infolist[0]);

        //加载机构下的作者放在加载院系执行完后

        //加载署名顺序
        $("signorder0").value = infolist[3];
        //加载署名本校信息
        var r = document.getElementsByName("issign");
        for (var i = 0; i < r.length; i++) {
            if (r[i].value == infolist[4]) {
                r[i].checked =true;
            }
        }
        r = null;
        //加载贡献率信息
        $("rate0").value = infolist[5];
        //加载备注信息
        $("note0").value = infolist[6];
        aid = infolist[7]; //保存返回的作者的主键，用于修改标识
        infolist = null;
    }
    else{

    }
}

function autInfo0_Wait() {

}

function autInfo1_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location = "../index.html";
    }
    else if (req.responseText != "false") {
        var infolist = req.responseText.split(",");
        //设置界面信息
        $("anum").value = infolist[0];
        $("aname1").value = infolist[1];
        $("subject").value = infolist[2];
        $("tel1").value = infolist[3];
        $("class").value = infolist[4];
        var r = document.getElementsByName("sex1");
        for (var i = 0; i < r.length; i++) {
            if (r[i].value == infolist[5]) {
                r[i].checked = "checked";
            }
        }
        r = null;
        $("addr1").value = infolist[6];
        $("rate1").value = infolist[7];
        $("signorder1").value = infolist[8];
        $("note1").value = infolist[9];
        aid = infolist[10]; //保存返回的作者的主键，用于修改标识
        infolist = null;
    }
    else {

    }
}

function autInfo1_Wait() {

}

function autInfo2_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location = "../index.html";
    }
    else if (req.responseText != "false") {
        var infolist = req.responseText.split(",");
        //设置界面信息
        $("aname2").value = infolist[0];
        $("educational").value = infolist[1];
        var r = document.getElementsByName("sex2");
        for (var i = 0; i < r.length; i++) {
            if (r[i].value == infolist[2]) {
                r[i].checked = "checked";
            }
        }
        r = null;
        $("professional").value = infolist[3];
        $("citizenship").value = infolist[4];
        $("tel2").value = infolist[5];
        $("company").value = infolist[6];
        $("addr2").value = infolist[7];
        $("rate2").value = infolist[8];
        $("signorder2").value = infolist[9];
        $("note2").value = infolist[10];
        aid = infolist[11]; //保存返回的作者的主键，用于修改标识
        infolist = null;
    }
    else {

    }
}

function autInfo2_Wait() {

}

//保存本校老师作者的修改信息
function saveEdit0() {
    if (checkAuthor(0)) {
        var issign_value = "";
        var r = document.getElementsByName("issign");
        for (var i = 0; i < r.length; i++) {
            if (r[i].checked) {
                issign_value = r[i].value;
            }
        }
        r = null;
        var url = "Handler.ashx";
        var pars = "act=EditAut0&id=" + $("code").value + "&aut=" + $("aut").options[document.getElementById('aut').selectedIndex].value + "&signorder=" + $("signorder0").value + "&rate=" + $("rate0").value + "&issign=" + issign_value + "&note=" + escape($("note0").value) + "&aid=" + aid;
        Ajax(url, pars, "get", editAut0_Complete, editAut0_Wait, true);
        url = null;
        pars = null;
    }
}

function editAut0_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location = "../index.html";
    }
    else if (req.responseText == "repeat") {
        $("loginstate").innerHTML = "作者重复";
    }
    else if (req.responseText == "true") {
        $("loginstate").innerHTML = "修改成功";
        delrow($("autlist"), row);
        addrow("autlist", new Array($("signorder0").value, $("aut").options[document.getElementById("aut").selectedIndex].text, $("Department").options[document.getElementById('Department').selectedIndex].text, $("rate0").value + "%", "本校老师", "<a href='javascript:void(0);' onclick=\"showEdit('" + $("aut").options[document.getElementById("aut").selectedIndex].value + "','" + $("code").value + "',0,this.parentNode.parentNode)\">编辑</a>&nbsp;<a href='javascript:void(0);' onclick=\"if(confirm('确定删除该作者吗？'))autDel0('" + $("aut").options[document.getElementById("aut").selectedIndex].value + "','" + $("code").value + "',this.parentNode.parentNode.parentNode,this.parentNode.parentNode)\">删除</a>"));
        setTimeout("closeAuthor()", 200);
        getAllRate(); //计算总贡献率
    }
    else if (req.responseText == "false") {
        $("loginstate").innerHTML = "修改发生错误";
    }
}

function editAut0_Wait() {
    $("loginstate").style.innerHTML = "<img src='../IMG/savepro.gif' />";
}


//保存本校学生作者的修改信息
function saveEdit1() {
    if (checkAuthor(1)) {
        var sex_value = "";
        var r = document.getElementsByName("sex1");
        for (var i = 0; i < r.length; i++) {
            if (r[i].checked) {
                sex_value = r[i].value;
            }
        }
        r = null;
        var url = "Handler.ashx";
        var pars = "act=EditAut1&id=" + $("code").value + "&anum=" + escape($("anum").value) + "&aname=" + escape($("aname1").value) + "&subject=" + escape($("subject").value) + "&tel=" + escape($("tel1").value) + "&class=" + escape($("class").value) + "&sex=" + escape(sex_value) + "&addr=" + escape($("addr1").value) + "&rate=" + $("rate1").value + "&signorder=" + $("signorder1").value + "&note=" + escape($("note1").value) + "&aid=" + aid;
        Ajax(url, pars, "get", editAut1_Complete, editAut1_Wait, true);
        url = null;
        pars = null;
    }
}

function editAut1_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location = "../index.html";
    }
    else if (req.responseText == "repeat") {
        $("loginstate").innerHTML = "作者重复";
    }
    else if (req.responseText == "true") {
        $("loginstate").innerHTML = "修改成功";
        delrow($("autlist"), row);
        addrow("autlist", new Array($("signorder1").value, $("aname1").value, "--", $("rate1").value + "%", "本校学生", "<a href='javascript:void(0);' onclick=\"showEdit('" + $("anum").value + "','" + $("code").value + "',1,this.parentNode.parentNode)\">编辑</a>&nbsp;<a href='javascript:void(0);' onclick=\"if(confirm('确定删除该作者吗？'))autDel1('" + $("anum").value + "','" + $("code").value + "',this.parentNode.parentNode.parentNode,this.parentNode.parentNode)\">删除</a>")); setTimeout("closeAuthor()", 200);
        getAllRate(); //计算总贡献率
    }
    else if (req.responseText == "false") {
        $("loginstate").innerHTML = "修改发生错误";
    }
}

function editAut1_Wait() {
    $("loginstate").style.innerHTML = "<img src='../IMG/savepro.gif' />";
}

//保存外校人员作者的修改信息
function saveEdit2() {
    if (checkAuthor(2)) {
        var sex_value = "";
        var r = document.getElementsByName("sex2");
        for (var i = 0; i < r.length; i++) {
            if (r[i].checked) {
                sex_value = r[i].value;
            }
        }
        r = null;
        var url = "Handler.ashx";
        var pars = "act=EditAut2&id=" + $("code").value + "&aname=" + escape($("aname2").value) + "&educational=" + escape($("educational").value) + "&company=" + escape($("company").value) + "&tel=" + escape($("tel2").value) + "&professional=" + escape($("professional").value) + "&citizenship=" + $("citizenship").value + "&sex=" + escape(sex_value) + "&addr=" + escape($("addr2").value) + "&rate=" + $("rate2").value + "&signorder=" + $("signorder2").value + "&note=" + escape($("note2").value) + "&aid=" + aid;
        Ajax(url, pars, "get", editAut2_Complete, editAut2_Wait, true);
        url = null;
        pars = null;
    }
}

function editAut2_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location = "../index.html";
    }
    else if (req.responseText == "repeat") {
        $("loginstate").innerHTML = "作者重复";
    }
    else if (req.responseText == "true") {
        $("loginstate").innerHTML = "修改成功";
        delrow($("autlist"), row);
        addrow("autlist", new Array($("signorder2").value, $("aname2").value, $("company").value, $("rate2").value + "%", "外校人员", "<a href='javascript:void(0);' onclick=\"showEdit('" + $("citizenship").value + "','" + $("code").value + "',2,this.parentNode.parentNode)\">编辑</a>&nbsp;<a href='javascript:void(0);' onclick=\"if(confirm('确定删除该作者吗？'))autDel2('" + $("citizenship").value + "','" + $("code").value + "',this.parentNode.parentNode.parentNode,this.parentNode.parentNode)\">删除</a>"));
        setTimeout("closeAuthor()", 200);
        getAllRate(); //计算总贡献率
    }
    else if (req.responseText == "false") {
        $("loginstate").innerHTML = "修改发生错误";
    }
}

function editAut2_Wait() {
    $("loginstate").style.innerHTML = "<img src='../IMG/savepro.gif' />";
}

//计算总贡献率
function getAllRate() {
    var rn = $("autlist").rows.length;
    var ratenum = 0;
    for (var i = 1; i < rn; i++) {
        ratenum += parseInt($("autlist").rows[i].cells[3].innerHTML.substring(0, $("autlist").rows[i].cells[3].innerHTML.length-1));
    }
    $("allrate").innerHTML = ratenum;
    contribution_temp = ratenum;
}

//获取作者列表数据
function getAutList() {
    var url = "Handler.ashx";
    var pars = "act=GetAutList&tcode=" + $("code").value;
    Ajax(url, pars, "get", getAutList_Complete, getAutList_Wait, true);
    url = null;
    pars = null;
}

function getAutList_Complete(req) {
    if (req.responseText == "uid_out") {
        alert("登录超时");
        parent.location = "../index.html";
    }
    else if (req.responseText != "") {
        var num = 0;
        eval("s =" + req.responseText);
        num = s.num;
        if (num > 0) {
            for (j = 0; j < num; j++) {
                if (s.lists[j].auttype == "本校老师") {
                    addrow("autlist", new Array(s.lists[j].signorder, s.lists[j].aname, s.lists[j].company, s.lists[j].rate, s.lists[j].auttype, "<a href='javascript:void(0);' onclick=\"showEdit('" + s.lists[j].pnum + "','" + s.lists[j].tcode + "',0,this.parentNode.parentNode)\">编辑</a>&nbsp;<a href='javascript:void(0);' onclick=\"if(confirm('确定删除该作者吗？'))autDel0('" + s.lists[j].pnum + "','" + s.lists[j].tcode + "',this.parentNode.parentNode.parentNode,this.parentNode.parentNode)\">删除</a>"));
                }
                else if (s.lists[j].auttype == "本校学生") {
                    addrow("autlist", new Array(s.lists[j].signorder, s.lists[j].aname, s.lists[j].company, s.lists[j].rate, s.lists[j].auttype, "<a href='javascript:void(0);' onclick=\"showEdit('" + s.lists[j].snum + "','" + s.lists[j].tcode + "',1,this.parentNode.parentNode)\">编辑</a>&nbsp;<a href='javascript:void(0);' onclick=\"if(confirm('确定删除该作者吗？'))autDel1('" + s.lists[j].snum + "','" + s.lists[j].tcode + "',this.parentNode.parentNode.parentNode,this.parentNode.parentNode)\">删除</a>"));

                }
                else if (s.lists[j].auttype == "外校人员") {
                    addrow("autlist", new Array(s.lists[j].signorder, s.lists[j].aname, s.lists[j].company, s.lists[j].rate, s.lists[j].auttype, "<a href='javascript:void(0);' onclick=\"showEdit('" + s.lists[j].citizenship + "','" + s.lists[j].tcode + "',2,this.parentNode.parentNode)\">编辑</a>&nbsp;<a href='javascript:void(0);' onclick=\"if(confirm('确定删除该作者吗？'))autDel2('" + s.lists[j].citizenship + "','" + s.lists[j].tcode + "',this.parentNode.parentNode.parentNode,this.parentNode.parentNode)\">删除</a>"));
                }
            }
        }
        getAllRate();
    }
}

function getAutList_Wait() {
    
}

window.onload = function() {
    $("Department").length = 0;
    AddOption("请选择", "", "Department");
    $("institution").length = 0;
    AddOption("请选择", "", "institution");
    $("aut").length = 0;
    AddOption("请选择", "", "aut");
    //获取作者信息
    getAutList();
}

